#pragma once
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<stdio.h>
#define MESSAGE_LENGTH 128
#define INFO_LENGTH 64

//using namespace std;

enum CMD {
	CMD_ERROR,
	CMD_REGISTER,
	CMD_REGISTER_RESULT,
	CMD_LOGIN,
	CMD_LOGIN_RESULT,
	CMD_LOGOUT,
	CMD_LOGOUT_RESULT,
	CMD_NEW_USER_JOIN,
	CMD_SEND_MESSAGE,
	CMD_BROADCAST,
	CMD_BROADCAST_RETURN,
	CMD_CHAT,
	CMD_CHAT_RESULT,
	CMD_TIME_OUT,
	CMD_PLAY,
	CMD_PLAY_RESULT,
	CMD_PLAY_INVITE,
	CMD_PLAY_INVITE_RESULT,
	CMD_PLAY_INVITE_RECEIVE
};

struct DataHeader
{
	DataHeader() {
		datalength = sizeof(DataHeader);
	}
	short datalength;
	short cmd;
};

struct Register :public DataHeader
{
	Register() {
		datalength = sizeof(Register);
		cmd = CMD_REGISTER;
	}
	char userName[INFO_LENGTH];
	char passWord[INFO_LENGTH];
};

struct RegisterResult :public DataHeader
{
	RegisterResult() {
		datalength = sizeof(RegisterResult);
		cmd = CMD_REGISTER_RESULT;
	}
	int result;
};

struct Login :public DataHeader
{
	Login() {
		datalength = sizeof(Login);
		cmd = CMD_LOGIN;
	}
	char userName[INFO_LENGTH];
	char passWord[INFO_LENGTH];
	int repeatLogFlag;
};
struct LoginResult :public DataHeader
{
	LoginResult() {
		datalength = sizeof(LoginResult);
		cmd = CMD_LOGIN_RESULT;
	}
	int result;
};

struct Logout :public DataHeader
{
	Logout() {
		datalength = sizeof(Logout);
		cmd = CMD_LOGOUT;
	}
	char userName[INFO_LENGTH];
	int loginFlag;
};

struct LogoutResult :public DataHeader
{
	LogoutResult() {
		datalength = sizeof(LogoutResult);
		cmd = CMD_LOGOUT_RESULT;
	}
	int result;
};

struct NewUserJoin :public DataHeader
{
	NewUserJoin() {
		datalength = sizeof(NewUserJoin);
		cmd = CMD_NEW_USER_JOIN;
		newUserID = 0;
	}
	int newUserID;
};

struct SendMess :public DataHeader
{
	SendMess() {
		datalength = sizeof(SendMess);
		cmd = CMD_SEND_MESSAGE;
	}
	char message[MESSAGE_LENGTH];
	char from[INFO_LENGTH];
};

struct Broadcast :public DataHeader
{
	Broadcast() {
		datalength = sizeof(Broadcast);
		cmd = CMD_BROADCAST;
	}
	char userName[INFO_LENGTH];
	char broadcastMessage[MESSAGE_LENGTH];
};

struct BroadcastReturn :public DataHeader
{
	BroadcastReturn() {
		datalength = sizeof(BroadcastReturn);
		cmd = CMD_BROADCAST_RETURN;
	}
	char userName[INFO_LENGTH];
	char broadcastReturnMessage[MESSAGE_LENGTH];
};

struct Chat :public DataHeader
{
	Chat() {
		datalength = sizeof(Chat);
		cmd = CMD_CHAT;
	}
	char dist[INFO_LENGTH];
	char from[INFO_LENGTH];
	char message[MESSAGE_LENGTH];
};

struct ChatResult :public DataHeader
{
	ChatResult() {
		datalength = sizeof(ChatResult);
		cmd = CMD_CHAT_RESULT;
	}
	char dist[INFO_LENGTH];
	char from[INFO_LENGTH];
	char message[MESSAGE_LENGTH];
	int result;
};

struct Play :public DataHeader
{
	Play() {
		datalength = sizeof(Play);
		cmd = CMD_PLAY;
	}
	char player[INFO_LENGTH];
	char player2[INFO_LENGTH];
	int def;
	int att;
};

struct PlayResult :public DataHeader
{
	PlayResult() {
		datalength = sizeof(PlayResult);
		cmd = CMD_PLAY_RESULT;
		result = -1;
	}
	int result;
};

struct PlayInvite :public DataHeader
{
	PlayInvite() {
		datalength = sizeof(PlayInvite);
		cmd = CMD_PLAY_INVITE;
	}
	char player[INFO_LENGTH];
	char player2[INFO_LENGTH];
};

struct PlayInviteResult :public DataHeader
{
	PlayInviteResult() {
		datalength = sizeof(PlayInviteResult);
		cmd = CMD_PLAY_INVITE_RESULT;
		result = -1;
	}
	char player[INFO_LENGTH];
	char player2[INFO_LENGTH];
	int result;
};

struct ReceiveInvite :public DataHeader
{
	ReceiveInvite() {
		datalength = sizeof(ReceiveInvite);
		cmd = CMD_PLAY_INVITE_RECEIVE;
		result = -1;
	}
	char player[INFO_LENGTH];
	char player2[INFO_LENGTH];
	int result;
};